home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / windows / wdj1096.zip / ESPOSITO.ZIP / W16EXT.C < prev    next >
C/C++ Source or Header  |  1996-07-25  |  6KB  |  186 lines

  1. #include "w16defs.h"
  2. #include "w16ext.h"
  3. #include <string.h>
  4.  
  5. #define APP_CLASS   "w16ext_class"
  6. #define APP_NAME    "Win16 features"
  7. #define APP_ABOUT   "How to inherit some special features " \
  8.     "from Windows 95\nby Dino Esposito"
  9. #define APP_HELPFILE "w16ext.hlp"
  10.  
  11. HANDLE happInst;       /* instance of the application   */
  12. HWND   hwndMain;       /* handle of the main window     */
  13.  
  14. /* GetScreenRect() - obtain rectangle that covers screen.
  15.  *
  16.  * This function takes into account the size of the task tray.
  17.  */
  18. int GetScreenRect(RECT* Rect)
  19.     {
  20.     HWND    TaskTray;
  21.     RECT    Screen = {0, 0, 0, 0};
  22.     RECT    Available;
  23.     Screen.right    = GetSystemMetrics(SM_CXSCREEN);
  24.     Screen.bottom   = GetSystemMetrics(SM_CYSCREEN);
  25.     Available       = Screen;
  26.     TaskTray = FindWindow("Shell_TrayWnd", NULL);
  27.     if(TaskTray != 0)
  28.         {
  29.         RECT TrayRect;
  30.         GetWindowRect(TaskTray, &TrayRect);
  31.         SubtractRect(&Available, &Screen, &TrayRect);
  32.         }
  33.     *Rect   = Available;
  34.     return TRUE;
  35.     }
  36.  
  37. // Module Private Functions
  38. void MPF_OnContextMenu( WPARAM wParam, LPARAM lParam )
  39. {
  40.     HMENU hmenu = LoadMenu( happInst, "APP_CONTEXTMENU" );
  41.     hmenu = GetSubMenu(hmenu,0);
  42.     TrackPopupMenu( hmenu, TPM_LEFTALIGN, LOWORD(lParam),
  43.         HIWORD(lParam), 0, (HWND)wParam, NULL );
  44.     DestroyMenu( hmenu );
  45. }
  46.  
  47. void MPF_OnDisplayChange( WPARAM wParam, LPARAM lParam )
  48. {
  49.     char szMsg[128];
  50.     wsprintf( szMsg, "The display size is now changed to %d x %d x %d", LOWORD(lParam), HIWORD(lParam), wParam );
  51.     MessageBox( hwndMain, szMsg, APP_NAME, MB_OK );
  52. }
  53.  
  54. DWORD MPF_GetHelpTopic( UINT uiID )
  55. {
  56.     switch( uiID )
  57.     {
  58.         case IDOK: return 4;
  59.         case IDC_TEXT: return 3;
  60.         case IDI_ICON: return 2;
  61.     }
  62.    return 0;
  63. }
  64. LRESULT CALLBACK __export AppDlgProc( HWND hDlg, UINT uiMsg,
  65.         WPARAM wParam, LPARAM lParam )
  66. {
  67.     static int siHelp=0;
  68.  
  69.     switch( uiMsg )
  70.         {
  71.         case WM_INITDIALOG:
  72.             SetWindowLong( hDlg, GWL_EXSTYLE, GetWindowLong( hDlg, GWL_EXSTYLE )|WS_EX_CLIENTEDGE|WS_EX_CONTEXTHELP);
  73.             SetWindowLong( hDlg, GWL_STYLE, GetWindowLong( hDlg, GWL_STYLE )|DS_3DLOOK );
  74.             SetWindowPos( hDlg, GetParent(hDlg), 0,0,0,0,SWP_DRAWFRAME|SWP_NOSIZE|SWP_NOMOVE );
  75.             SetFocus( hDlg );
  76.             break;
  77.         case WM_SYSCOMMAND:
  78.             siHelp = (wParam==SC_CONTEXTHELP);
  79.             DefWindowProc( hDlg, uiMsg, wParam, lParam );
  80.             siHelp=0;
  81.             return 1;
  82.         case WM_HELP:
  83.             if( siHelp )
  84.                 {
  85.                 LPHELPINFO lphi = (LPHELPINFO)lParam;
  86.                 WinHelp( hDlg, APP_HELPFILE, HELP_CONTEXTPOPUP,
  87.                     MPF_GetHelpTopic((UINT)lphi->hItemHandle) );
  88.                 }
  89.             else
  90.                 WinHelp( hDlg, APP_HELPFILE, HELP_CONTEXT, 5 );
  91.             return 1;
  92.         default:
  93.             if( uiMsg==WM_COMMAND )
  94.                 EndDialog( hDlg, TRUE );
  95.         }
  96.     return 0L;
  97. }
  98.  
  99.  
  100. LRESULT CALLBACK __export AppWndProc( HWND hwnd, UINT uiMsg,
  101.         WPARAM wParam, LPARAM lParam )
  102. {
  103.     switch( uiMsg )
  104.         {
  105.         case WM_COMMAND:
  106.         switch( wParam )
  107.             {
  108.             case IDM_FILEDIALOG:
  109.                 return DialogBox( happInst, "DLG_TEST", hwnd,
  110.                     (DLGPROC)AppDlgProc );
  111.             case IDM_FILEEXIT:
  112.                 SendMessage( hwndMain, WM_CLOSE, 0, 0L );
  113.                 break;
  114.             case IDM_HELPABOUT:
  115.                 MessageBox( hwndMain, APP_ABOUT, APP_NAME, MB_ICONINFORMATION|MB_OK );
  116.                 break;
  117.             }
  118.             break;
  119.         case WM_LBUTTONDBLCLK:
  120.             {
  121.             RECT    Available;
  122.             GetScreenRect(&Available);
  123.             MoveWindow(hwndMain, Available.left, Available.top,
  124.                 Available.right-Available.left,
  125.                 Available.bottom-Available.top, TRUE);
  126.             }
  127.             break;
  128.         case WM_HELP:
  129.             WinHelp( hwndMain, APP_HELPFILE, HELP_CONTENTS, 0 );
  130.             break;
  131.         case WM_CONTEXTMENU:
  132.             MPF_OnContextMenu(wParam, lParam);
  133.             break;
  134.         case WM_DEVICECHANGE:
  135.             MessageBox( hwndMain, "Received a WM_DEVICECHANGE "
  136.                 "message", APP_NAME, MB_OK );
  137.             break;
  138.         case WM_DISPLAYCHANGE:
  139.             MPF_OnDisplayChange(wParam, lParam);
  140.             break;
  141.         case WM_CLOSE:
  142.             WinHelp( hwndMain, APP_HELPFILE, HELP_QUIT, 0 );
  143.             break;
  144.         case WM_DESTROY:
  145.             PostQuitMessage(0);
  146.             break;
  147.     }
  148.     return DefWindowProc( hwnd, uiMsg, wParam, lParam );
  149. }
  150.  
  151. #ifdef __BORLANDC__
  152. #pragma argsused
  153. #endif
  154. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevious,
  155.     LPSTR lpszCmdLine, int iCmdShow)
  156. {
  157.     MSG msg;
  158.  
  159.     happInst = hInstance;
  160.     if( !hPrevious )
  161.         {
  162.         WNDCLASS wc;
  163.         memset( &wc, 0, sizeof(WNDCLASS) );
  164.         wc.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
  165.         wc.lpfnWndProc = (WNDPROC)AppWndProc;
  166.         wc.hInstance = hInstance;
  167.         wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW+1);
  168.         wc.lpszMenuName = "APP_MENU";
  169.         wc.lpszClassName = APP_CLASS;
  170.         RegisterClass( &wc );
  171.         }
  172.  
  173.     hwndMain=CreateWindowEx(WS_EX_OVERLAPPEDWINDOW|WS_EX_TOOLWINDOW,
  174.         APP_CLASS, APP_NAME, WS_OVERLAPPEDWINDOW, 0, 0, 400, 300,
  175.         NULL, NULL, hInstance, NULL );
  176.     ShowWindow( hwndMain, iCmdShow );
  177.     UpdateWindow( hwndMain );
  178.     while( GetMessage( &msg, NULL, NULL, NULL ) )
  179.         {
  180.         TranslateMessage( &msg );
  181.         DispatchMessage( &msg );
  182.         }
  183.     return msg.wParam;
  184. }
  185.  
  186.